package game;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;

public class Mouse implements MouseListener, MouseMotionListener {

	static private Mouse instance = null;
	
	private List<Integer> mouseCode = new ArrayList<Integer>();
	private Point positionMouse = new Point(0,0);
	
	static public Mouse getInstance()
	{
		if (instance == null)
		{
			instance = new Mouse();
		}
		
		return instance;
	}
	
	public void mouseClicked(MouseEvent m) {}
	public void mouseEntered(MouseEvent m) {}
	public void mouseExited(MouseEvent m) {}

	public void mousePressed(MouseEvent m) {
		int aux = m.getButton();
		for (int i : mouseCode)
			if (i == aux)
				return;
		
		this.mouseCode.add(aux);
	}

	public void mouseReleased(MouseEvent m) {
		int aux = m.getButton();
		
		for (int i = 0; i < mouseCode.size(); i++)
		{
			if (mouseCode.get(i) == aux)
			{
				this.mouseCode.remove(i);		
			}
		}
	}
	
	public boolean isMousePressed(int m)
	{
		for (int i: mouseCode)
		{
			if (i == m)
			{
				return true;
			}
		}
		
		return false;
	}
	
	public void mouseDragged(MouseEvent m) {
		this.positionMouse = new Point(m.getX(), m.getY());
	}
	
	public void mouseMoved(MouseEvent m) {
		this.positionMouse = new Point(m.getX(), m.getY());
	}
	
	public Point getPositionMouse() {
		return positionMouse;
	}
}
